<?php
require_once 'application/models/AbstractModel.php';
require_once 'application/models/SousMenu.php';

class MenuPrincipal extends AbstractModel
{
    protected $_name = 'Menu_principal';
    
    protected $_dependentTables = array('SousMenu');
    
    protected $_referenceMap    = array(
        'Menu' => array(
            'columns'           => 'menu_id',
            'refTableClass'     => 'Menu',
            'refColumns'        => 'id',
    		'onDelete'          => self::CASCADE_RECURSE
        )
    );

    function __construct() {
        parent::__construct();
    	$this->_fieldsToDisplay = array('id', 'menu_id', 'nom', 'sort_order');
    }
   
    function getObjectFromRow($row) {
    	$object = $this->getArrayFromRow($row);
    	
	    $tableSM = new SousMenu();
		
		$select = $this->select()->order('sort_order ASC');
	    $sMRows = $row->findDependentRowset('SousMenu', 'SousMenu', $select);
	    
	    $smList = array();
	    foreach ($sMRows as $sMRow) {
	    	$smList[] = $tableSM->getArrayFromRow($sMRow);
	    }
	    $object['sousmenu'] = $smList;
  		    
	    return $object;
    }
}
    	